<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>民族研究档案库</title>
    <link rel="stylesheet" type="text/css" href="./css/write-two.css" /> 
    <style>
        html,body{
            height: 100%;
        }
    </style>
</head>

<body>
    <div class="loading-warp">
		<div class="loading">
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
		</div>
	</div>
    <!--startprint-->
    <div class="startprint-main">
        <img src="" alt="">
    </div>
    <!--endprint-->

    <script src="./js/jquery.min.js"></script>
    <script>
        console.log(sessionStorage.getItem("startprint"))
        const startprintStr = sessionStorage.getItem("startprint") 
        $(".startprint-main img").attr("src",startprintStr)
        $(".loading-warp").show()
        setTimeout(()=>{
            $(".loading-warp").hide() 
            print_page()
        },1200)
        function print_page() { 
            if (!!window.ActiveXObject || "ActiveXObject" in window) {
                remove_ie_header_and_footer();
            }
            bdhtml = window.document.body.innerHTML; //获取当前页的html代码
            sprnstr = "<!--startprint-->"; //设置打印开始区域
            eprnstr = "<!--endprint-->";//设置打印结束区域
            prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);//从开始代码向后取html
            prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));//从结束代码向前取html
            window.document.body.innerHTML = prnhtml;
            window.print();
            // 这里延迟关闭是因为在加载的东西比较多的时候，可能dom需要的数据还没加载完就关闭了。这样会导致数据显示不全，所以采用延迟关闭的方法防止数据不全。具体延迟多长时间自己控制。
            setTimeout(cancle, 5000);
        };

        function remove_ie_header_and_footer() {
            var hkey_root, hkey_path, hkey_key;
            hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
            try {
                var RegWsh = new ActiveXObject("WScript.Shell");
                RegWsh.RegWrite(hkey_path + "header", "");
                RegWsh.RegWrite(hkey_path + "footer", "");
            } catch (e) { }
        }

        function cancle() {
            window.close();
        }
    </script>
</body>

</html>